<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>登陆注册页面</title>
  <style>
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }

    body {
      background-color: rgb(0, 0, 0, .5);
    }

    ul,
    li {
      list-style: none;
    }

    .login-wrapper {
      position: absolute;
      left: 50%;
      top: 50%;
      width: 400px;
      background-color: #fff;
      transform: translate3d(-50%, -50%, 0);
    }

    .login-header {
      display: flex;
      justify-content: center;
      align-items: center;
      height: 60px;
      color: #fff;
      background-color: sandybrown;
    }

    .login-content .list-item {
      padding: 15px;
    }

    .login-content .list-item .item {
      display: flex;
      align-items: center;
      padding: 15px 0;
      border-bottom: 1px solid #ddd;
    }

    .login-content .list-item .item .name {
      width: 80px;
      padding-right: 10px;
      text-align: justify;
      text-align-last: justify;
    }

    .login-content .list-item .item .ip-content {
      flex: 1;
    }

    .login-content .list-item .item .ip-content input {
      width: 100%;
      height: 30px;
      padding: 0 10px;
      line-height: 30px;
      outline: none;
      border: 1px solid #ccc;
    }

    .login-fotter {
      padding: 15px;
    }

    .login-fotter .btn {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 100%;
      height: 30px;
      margin-bottom: 15px;
      border: none;
      outline: none;
      cursor: pointer;
    }
  </style>
</head>

<body>
  <div class="container">
    <div class="login-wrapper">
      <div class="login-header">用户登陆</div>
      <div class="login-content">
        <ul class="list-item">
          <li class="item">
            <div class="name">用户名</div>
            <div class="ip-content"><input type="text" name="username" id="username" /></div>
          </li>
          <li class="item">
            <div class="name">密码</div>
            <div class="ip-content"><input type="password" name="password" id="password" /></div>
          </li>
        </ul>
      </div>
      <div class="login-fotter">
        <button class="btn" id="login">登陆</button>
        <button class="btn" id="reg">注册</button>
      </div>
    </div>
  </div>

  <script src="jquery.min.js"></script>
  <script>
    $("#login").on("click", function () {
      $.ajax({
        url: "/login",
        data: {
          username: $("#username").val(),
          password: $("#password").val()
        },
        dataType: "json",
        success(res) {
          if (res.err) {
            alert(res.msg);
          } else {
            alert("登陆成功");
            location.href = "admin.html";
          }
        }
      })
    });
    $("#reg").on("click", function () {
      $.ajax({
        url: "/reg",
        method: "POST",
        data: {
          username: $("#username").val(),
          password: $("#password").val()
        },
        dataType: "json",
        success(res) {
          if (res.err) {
            alert(res.msg);
          } else {
            alert("注册成功");
          }
        }
      })
    });    
  </script>
</body>

</html>